import React from 'react';
import TableStore from '../../stores/mobxTable/table';
import { observer } from 'mobx-react';
import Table from '../../view/view-table';
import TableCell from './table-cell';

export interface MobxTableProps {
    tableStore: TableStore;
    scroll?: {
        x?: number | string,
        y?: number | string
    };
    pagination?: any;
    isMergeLine?:boolean;
    isRowSelection?:any;
    isfrontmultlang?:boolean;
    isNoSwitchEditStatus?:boolean;//是否去掉鼠标点击切换修改状态
}
@observer
export default class MobxTable extends React.Component<MobxTableProps, any> {
    render() {
        const { tableStore, scroll, pagination,isMergeLine=false,isRowSelection=true} = this.props;
        const rowSelection = isRowSelection&&{
            onChange: (selectedRowKeys) => {
                tableStore.onSelectedRowChange(selectedRowKeys);
            },
            getCheckboxProps: record => ({
                disabled: record.name === 'Disabled User', // Column configuration not to be checked
                name: record.name,
            }),
            selectedRowKeys: tableStore.selectedRowKeys.slice()
        };
        let className = "cube-mobx-table cube-mobx-table-tbody-tr-td-lk";
        if(isMergeLine){
            className = "cube-mobx-table cube-mobx-table-tbody-tr-td-lk mergeLine";
        }
        return (
            [<Table
                loading={tableStore.loading}
                className={className}
                rowSelection={rowSelection}
                renderCell={this.renderCell}
                columns={tableStore.columns&&tableStore.columns.slice()}
                scroll={{...scroll}}
                rowKey={this.rowKey}
                pagination={pagination}
                dataSource={tableStore.datas.slice()}
            />
            ]
        )
    }
    rowKey = (record) => {
        return record;
    }
    renderCell = (column: any, randomkey: string) => {
        const { tableStore,isNoSwitchEditStatus,isfrontmultlang} = this.props;
        return (
            <TableCell
                column={column}
                randomkey={randomkey}
                tableStore={tableStore}
                isfrontmultlang={isfrontmultlang}
                isNoSwitchEditStatus={isNoSwitchEditStatus}
            />
        )
    }
}
